$(document).ready(function() {
    query();

});

var query=function () {
    $.ajax({
        url: "http://localhost:8080/student/queryStudentByStuNum",
        type: "GET",
        async: true,
        data: "stuNum=" + 20151000,
        dataType: "json",
        success: function (data) {
            //console.log(data);
            //console.log(data.data);
            console.log(data.data.student);
            console.log(data.data.student.stuName);


            var student=data.data.student;
            $("#stuName").html(student.stuName);
            $("#stuNum").html(student.stuNum);
            if (student.stuSex==0) {
                $("#stuSex").html("男");
            }else {
                $("#stuSex").html("女");
            }
            $("#stuAcademy").html(student.academyName);
            $("#stuGrade").html(student.stuGrade);
            $("#stuNation").html(student.stuNation);
            $("#stuNativeplace").html(student.stuNativeplace);
            if (student.stuPoli==0){
                $("#stuPoli").html("群众");
            }else if (student.stuPoli==1) {
                $("#stuPoli").html("积极分子");
            }else if (student.stuPoli==2) {
                $("#stuPoli").html("发展对象");
            }else if (student.stuPoli==3) {
                $("#stuPoli").html("中共预备党员");
            }else{
                $("#stuPoli").html("中共党员");
            }

            if((student.cet4Grade!=null)&&(student.cet6Grade!=null)){
                $("#stuCet46").html("CET-4："+student.cet4Grade+",CET-6:"+student.cet6Grade);
            }else if((student.cet4Grade!=null)&&(student.cet6Grade==null)){
                $("#stuCet46").html("CET-4："+student.cet4Grade);
            }else if((student.cet4Grade==null)){
                $("#stuCet46").html("暂无成绩");
            }

            $("#stuBirthday").html(student.stuBirthday);
            $("#stuIdcardNum").html(student.stuIdcardNum);
            $("#stuPhone").html(student.stuPhone);

        },
        error:function () {
            layer.msg("网络在开小差~稍后重试");
        }
    });
}

$(document).on('click', '#updatePerson', function () {
    //获取$stuNum
    var $stuNum = 20151000;
    console.log($stuNum);
    //页面层
    layer.open({
        type: 2,
        title: '修改身份信息',
        area: ['800px', '800px'],
        content: ['personUpdate.html?stuNum='+$stuNum, 'no']
    })
})

$(document).on('click', '#download', function() {
    console.log($("#stuName").text());
    var $stuNum =$("#stuNum").text();
    var $stuName=$("#stuName").text();
    var $stuSex=$("#stuSex").text();
    var $stuIdcardNum=$("#stuIdcardNum").text();
    var $stuBirthday=$("#stuBirthday").text();
    var $stuNation =$("#stuNation").text();
    var $stuPoli=$("#stuPoli").text();
    var $stuPhone=$("#stuPhone").text();
    var $stuNativeplace=$("#stuNativeplace").text();
    var $stuGrade=$("#stuGrade").text();
    var $cet46Grade=$("#stuCet46").text();
    var $academyName=$("#stuAcademy").text();
console.log("stuNum=" + $stuNum+"&stuName="+$stuName+"&stuSex="+$stuSex+"&stuIdcardNum="+$stuIdcardNum+"&stuBirthday="+$stuBirthday+"&stuNation="+ $stuNation+"&stuPoli="+$stuPoli+"&stuPhone="+$stuPhone+"&stuNativeplace="+$stuNativeplace+"&stuGrade="+$stuGrade+"&cet46Grade="+$cet46Grade+"&academyName="+$academyName);
    $.ajax({
        url: "http://localhost:8080/student/download",
        type: "GET",
        async: true,
        data: "stuNum=" + $stuNum+"&stuName="+$stuName+"&stuSex="+$stuSex+"&stuIdcardNum="+$stuIdcardNum+"&stuBirthday="+$stuBirthday+"&stuNation="+ $stuNation+"&stuPoli="+$stuPoli+"&stuPhone="+$stuPhone+"&stuNativeplace="+$stuNativeplace+"&stuGrade="+$stuGrade+"&cet46Grade="+$cet46Grade+"&academyName="+$academyName,
        dataType: "json",
        success:function () {
            layer.alert("已下载学生信息表！");
        },
        error:function () {
            layer.alert("下载失败，请重试！");
        }
    });
});